package com.example.f8399.testdemo;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.WindowManager;

import com.example.caughtglobalexceptionlibrary.CosmosException;
import com.example.f8399.testdemo.fragment.MyProgressDialog;

import io.reactivex.disposables.CompositeDisposable;
import transferObject.TransferObject;

/**
 * Created by f8399 on 2018/7/6.
 */

public  class BaseActivity extends AppCompatActivity {
    public CompositeDisposable mCompositeDisposable = new CompositeDisposable();
    public MyProgressDialog myProgressDialog = new MyProgressDialog();
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        //设置竖屏
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }


    }

    public void showProgress() {
        myProgressDialog.show(getFragmentManager(),"progressbar");
    }
    public void dismisssProgress() {
        myProgressDialog.dismiss();
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void goActivity(Class<?> pclass) {
        startActivity(new Intent(this, pclass));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mCompositeDisposable != null) {
            if (!mCompositeDisposable.isDisposed()) {
                mCompositeDisposable.dispose();
            }
        }
    }
}
